<!DOCTYPE html>
<html lang="ru">
<head>

<? 
function savelog($prefix)
{
    $f = fopen($_SERVER["DOCUMENT_ROOT"]."/log.txt", "a");
    fwrite($f, $prefix." - ".date("d.m.Y H:i:s")."\r\n");
    fclose($f);
}
?>
    
<? 
if (strpos($APPLICATION->GetCurPage(), "/index.php")>=0)
{
    $cur_date_week = date("w");
    if ($cur_date_week==0 || $cur_date_week==6)
        $night_mode = true;
    else
    {
        $cur_h = date("G");
        if (($cur_h >= 20) || ($cur_h < 8))
            $night_mode = true;
        else
            $night_mode = false;
    }
}
else
    $night_mode = false;
?>    
    
<? if ($night_mode): ?>
    
    <? savelog("night"); ?>
    <script>
        function reload()
        {
            window.location = "/plazma/";
        }
        window.setTimeout(reload, 10*60*1000);
    </script>

<? else: ?>
    
    <? savelog("day"); ?>
    <title><? $APPLICATION->ShowTitle(); ?></title>

    <script type="text/javascript" src="/bitrix/templates/plazma/js/jquery.min.1.10.2.js"></script>
    
    <? $APPLICATION->ShowHead(); ?>
    
    <script type="text/javascript" src="/bitrix/templates/plazma/js/html5.js"></script>
    <script type="text/javascript" src="/bitrix/templates/plazma/js/jquery.jcarousel.min.js"></script>
    
    <script type="text/javascript">
        $(function() {
                $('.jcarousel-pagination')
                    .on('jcarouselpagination:active', 'a', function() {
                        $(this).addClass('active');
                    })
                    .on('jcarouselpagination:inactive', 'a', function() {
                        $(this).removeClass('active');
                });            

                $('.jcarousel').on('jcarousel:visiblein', 'li', function(event, carousel) {
                    $('.jcarousel').jcarouselAutoscroll({
                            target: '+=1',
                            'interval': $(this).attr('interval') * 1000
                    });                    
                    $('div.countdown').html($(this).attr('interval'));
                });

                $('.jcarousel').jcarousel({
                        'wrap': 'circular',
                })
                $('.jcarousel-pagination').jcarouselPagination({
                        carousel: $('.jcarousel')
                });                
        });
        
        function reload()
        {
            window.location = "/plazma/";
        }
        window.setTimeout(reload, 30*60*1000);
        
        function countdown()
        {
            var cnt = $('div.countdown').html();
            if (cnt > 0)
                $('div.countdown').html(cnt-1);
        }
        window.setInterval(countdown, 1000);
    </script>

<? endif; ?>
    
</head>

<? if ($night_mode): ?>

    <body bgcolor='black'><?= date("H:i:s"); ?></body>
    <? die(); ?>

<? else: ?>

<body>
<div id="container">
    <header>
        <div id='logo'><img src='/bitrix/templates/plazma/img/logo3.png' width='146' height='126' alt='' /></div>
        <div id="company">ОАО &laquo;ВНИИАЭС&raquo; отделение АСУТП</div>
        <div id="address">Москва, ул. Ферганская, д. 25</div>
        <div id='phone'>8 495 651 91 46</div>
        <div class='spacer'></div>
    </header>

<? endif; ?>
